package com.skt.common_hr.medicalmoney_sac.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.medicalmoney_sac.MedicalMoneyFacade;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class medicalSubjectCodeProxy extends CommonProxy
	{
		public static const NAME:String = "medicalSubjectCodeProxy";


		//진료과목 
		public var acMedSubject:ArrayCollection;
		
		// 구분 
		public var acMedSubject2:ArrayCollection;

		public function medicalSubjectCodeProxy(data:Object=null)
		{
			super(NAME, data);
		}


		// 진료과목 콤보박스 내용
		public function loadMedSubjectCodes():void
		{
			var param:Object = new Object();
			//param["I_COGBN"] = corsn;

			loadData("Z_HR_0138", param, corsnResult2, corsnFault);
		}

		public function corsnResult2(event:ResultEvent):void
		{
			if(retCode==0) {
				acMedSubject = parseCorsn(event.result.OTAB);
				acMedSubject2 = parseCorsn2(event.result.OTAB1);
				facade.sendNotification(MedicalMoneyFacade.LOAD_MEDICALMONEY_MEDSUBJECT_COMPLETE, this);
			}
			else {
				facade.sendNotification(MedicalMoneyFacade.LOAD_MEDICALMONEY_MEDSUBJECT_FAILED, this);
			}
		}
		
		private function corsnFault(event:FaultEvent):void
		{
			facade.sendNotification(MedicalMoneyFacade.LOAD_MEDICALMONEY_MEDSUBJECT_FAILED, this);
		}
		
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 *
		 * @param ArrayCollection
		 * @return 진료과목 ArrayCollection
		 */
		private function parseCorsn(srcArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			
			retArr.addItem({label:'진료과목선택', data:-1});
			for each(var rec:Object in srcArr)
			{
				retArr.addItem({label:rec["MEDTX"], data:rec["MEDCD"]});
			}
			return retArr;
		}	
		
		private function parseCorsn2(srcArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			
			retArr.addItem({label:'구분선택', data:-1});
			for each(var rec:Object in srcArr)
			{
				retArr.addItem({label:rec["TEXT"], data:rec["CODE"]});
			}
			return retArr;
		}		

	}
}